﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using 医院预约Web.Models;

namespace 医院预约Web.Controllers
{
    public class DoctorController : Controller
    {
        public IActionResult Index()
        {
            string account = HttpContext.Session.GetString("name");
            ViewData["account"] = account;
            return View();
        }
        public IActionResult weekmessage(int id)
        {
            ViewData["id"] = id;
            return View();
        }
        public IActionResult Confirm()
        {
            string account = HttpContext.Session.GetString("name");
            ViewData["id"] = account;
            DataBase db = HttpContext.RequestServices.GetService(typeof(DataBase)) as DataBase;
            string date=DateTime.Today.ToShortDateString();
            return View(db.GetDoctorAppointment(account,date));
        }
        public IActionResult Confirm2(string createtime)
        {
            ViewData["createtime"] = createtime;
            return View();
        }
        [HttpPost]
        public void Confirm2(string input,string createtime)
        {
            DataBase db = HttpContext.RequestServices.GetService(typeof(DataBase)) as DataBase;
            if(db.ConfirmAppointment(createtime,input))
                Response.Redirect("/Admin/dialog?id=3");
            else Response.Redirect(Url.Action("LoginError", "Home"));
        }
        [HttpPost]
        public IActionResult WeekdboMessage(int id ,string w1, string w2, string w3, string w4, string w5, string w6, string w7)
        {
            //return id.ToString() + w1 + w2 + w3 + w4 + w5 + w6 + w7;
            string[] w = new string[7] { w1, w2, w3, w4, w5, w6, w7 };
            int[] iw = new int[7];
            for (int i = 0; i <= 6; i++)
            {
                if (w[i] == "on")
                {
                    iw[i] = 1;
                }
                else iw[i] = 0;
            }
            DataBase db = HttpContext.RequestServices.GetService(typeof(DataBase)) as DataBase;
            if(db.WeekdboMessage(id, iw[0], iw[1], iw[2], iw[3], iw[4], iw[5], iw[6])==false)
                Response.Redirect("/Admin/dialog?id=7");
            ViewData["ID"] =2;
            return View();
        }
    }
}